import $service from '../../../../service.js';
var doctor_id;
var that;
var this_;
const app = getApp();
Page({
    data:{
       patientList:[],
       prescriptionlist:[],
       doctor_name:''
    },
    onLoad(e){
        var doctor_name = e.doctor_name;
        this.setData({
            doctor_name : doctor_name
        })
    },
    onShow(){
        doctor_id = $service.getUserLocalStorage().doctor_id;
        this.getMysubscriber();
        this.getOpenPrescriptions();
    },
    //监听input
    inputChange(e){
      var doctor_name = e.detail.value;
      this.setData({
          doctor_name : doctor_name
      })
        this.getMysubscriber();
        this.getOpenPrescriptions();    
    },
    //查询患者
    getMysubscriber() {
        let params = {
            "current": 1,
            "maxTime": "",
            "minTime": "",
            "name": this.data.doctor_name,
            "size": 10
          }
        app.http.getMysubscriber(params).then(res => {
            this.setData({
                patientList : res.data.list
            })
        }).catch(err => {
            $service.showToast(err.msg);
        })
    },
    // 查询处方
    getOpenPrescriptions() {
        let params = {
            "current": 1,
            "endDate": "",
            "patientName":  this.data.doctor_name,
            "prescriptionState": "",
            "prescriptionType": "",
            "size": 10,
            "startDate": ""
          }
        app.http.getOpenPrescriptions(params).then(res => {
            this.setData({
                prescriptionlist : res.data.list
            })
        }).catch(err => {
            $service.showToast(err.msg);
        })
    },
    gotopage(e){
        var num = e.currentTarget.dataset.num;
        var index = e.currentTarget.dataset.index;
        if(num == 0){
            let patientInfo = JSON.stringify(this.data.patientList[index])
            $service.setStore('patientInfo', patientInfo)
            $service.openPage('../index_news/index_news_details/index_news_details?type=3')
        }else if(num == 1){
            $service.openPage('/pages/user_side/index/index_health_guidance/index_health_guidance?id=' + this.data.prescriptionlist[index].id + '&type=4' )
        }else if(num == 2){
            if(!$service.isUndefinedAndEmpty(this.data.doctor_name)){
                this.getMysubscriber();
                this.getOpenPrescriptions();
            }
        }
        
    }
})